<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

    <title>用户中心</title>
    <link href="/lender/css/bootstrap.min.css" rel="stylesheet">
    <link href="/lender/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/lender/css/style.min.css" rel="stylesheet">
    <link href="/lender/css/login.min.css" rel="stylesheet">
    <link href="/lender/css/bootstrap-table.css" rel="stylesheet">
    <script type="text/javascript" src="/lender/js/jquery.min.js"></script>
    <script type="text/javascript" src="/lender/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/lender/js/bootstrap-table.js"></script>
    <script type="text/javascript" src="/lender/js/bootstrap-table-zh-CN.js"></script>
    <script type="text/javascript" src="/lender/laydate/laydate.js"></script>
    <script type="text/javascript" src="/lender/layer/layer.js"></script>
</head>

<body class="gray-bg" style=" background-color: #fff">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="ibox float-e-margins" style="margin: 0;"> 
            <div class="ibox-content">
                <p >
                	<div class="input-group m-b" 
                		style="position:inherit;float:left;width:420px;margin-right: 15px;">
                            <input id="search_input" type="text" placeholder="用户名" class="form-control" style="height: 46px;">
							<span class="input-group-btn">
							<button class="btn btn-info btn-lg" id="search_btn" type="button">
								<a >
									<i class="fa fa-search"></i> 
								</a>
						</button>
					</span>
                    </div>
                    <button class="btn btn-primary  btn-lg" id="adduser" type="button">
                    	<i class="fa fa-plus"></i>&nbsp;添加
                    </button>
                    <button class="btn btn-success  btn-lg" id="updateuser" type="button">
                        <!-- <i class="fa fa-pencil-square-o"></i>&nbsp;修改 -->
                        <i class="fa fa-paste"></i>&nbsp;修改 
                    </button>
                    <button class="btn btn-warning  btn-lg" id="deluser" type="button">
                    	<i class="fa fa-trash"></i>&nbsp;删除 
                    </button>
                    <button class="btn btn-success  btn-lg" id="enauser" type="button">
                    	<i class="fa fa-heart"></i>&nbsp;启用 
                    </button>
                    <button class="btn btn-warning  btn-lg" id="disuser" type="button">
                    	<i class="fa fa-heart-o"></i>&nbsp;禁用 
                    </button>
                </p>
            </div>
        </div>
		<!-- bootstrap  table -->
		<div class="row" >
			<div class="col-xs-12 col-sm-12">
				<div class="ibox-content">
					<table id="user_table"  class="table table-hover"></table>
				</div>
			</div>
		</div>
    </div>
</body>
<script type="text/javascript">
var actionUrl = '/lender/login';
var size;
$(function(){
	size = {width:$(window).width(),height:$(window).height()};
	$('#adduser').click(function(){crud.adduser()});
	$('#updateuser').click(function(){crud.updateuser()});
	$('#deluser').click(function(){crud.deluser()});
	$('#enauser').click(function(){crud.endisuser(0)});
	$('#disuser').click(function(){crud.endisuser(1)});
	$('#search_btn').click(function(){
	    $('#user_table').bootstrapTable('refresh',{url: '/lender/userController/findAllUser.do'});
	}); 

	gmTable.Init();
});

$(window).resize(function() {
    $('#user_table').bootstrapTable('resetView', {
        height: tableHeight()
    })
})

function gmTable(){};
	gmTable.Init = function(){
		$('#user_table').bootstrapTable({
		    method: 'post',
		    url:"/lender/userController/findAllUser.do",//要请求数据的文件路径
		    //height:tableHeight(),//高度调整
		    //toolbar: '#toolbar',//指定工具栏
		    striped: true, //是否显示行间隔色
		    contentType: "application/x-www-form-urlencoded",//必须要有！！！！
		    pageNumber: 1, //初始化加载第一页，默认第一页
		    pagination:true,//是否分页
		    singleSelect:true,//设置单选
		    queryParamsType:'limit',//查询参数组织方式
		    queryParams:queryParams,//请求服务器时所传的参数
		    sidePagination:'server',//指定服务器端分页
		    pageSize:10,//单页记录数
		    pageList:[5,10,20,30],//分页步进值
		    showRefresh:false,//刷新按钮
		    showColumns:false,
		    clickToSelect: true,//是否启用点击选中行
		   // toolbar:'#toolbar',//指定工作栏
		    responseHandler:function(res){
		        //在ajax获取到数据，渲染表格之前，修改数据源
		        var params ={"total":res.total,"rows": res.data};
		       	return	params;  //数据
		    },
		    columns:[
		        {
		            title:'单选',
		            field:'select',
		            //复选框
		            checkbox:true,
		            width:25,
		            align:'center',
		            valign:'middle'
		        },
		        {
		            title:'用户名',
		            field:'userName',
		            visible:true, //隐藏 或者可见
		            align:'center',
		            valign:'middle'
		        },
		        {
		            title:'手机号码',
		            field:'phonenum',
		            align:'center',
		            valign:'middle'
		        },
		        {
		        	title:'状态',
			        field:'status',
			        align:'center',
			        valign:'middle',	
			        formatter: function (value, row, index) {
                        if(value==0){
                        	return "启用";
                        }else{
                        	return "禁用";
                        }
                    }
		        }
		        
		    ],
		    locale:'zh-CN'//中文支持,
		   
		}); 
	}
//三个参数，value代表该列的值
function operateFormatter(value,row,index){
    if(value==2){
        return '<i class="fa fa-lock" style="color:red"></i>'
    }else if(value==1){
        return '<i class="fa fa-unlock" style="color:green"></i>'
    }else{
        return '数据错误'
    }
}

//请求服务数据时所传参数
function queryParams(params){
    var json = null;
	var reg = new RegExp("^[0-9]*$");
	var obj = $('#search_input').val();
	var pageNumber = params.offset;
	if(reg.test(obj)){
	    return {
	    	//每页多少条数据
	    	pageSize: params.limit,
	    	//请求第几页
	    	pageIndex:pageNumber,
	    	   
    	   mobile:obj
        };
    }else{
	    return {
    	   //每页多少条数据
    	   pageSize: params.limit,
    	   //请求第几页
    	   pageIndex:pageNumber,
    	   
    	   name:obj
        };
	   
    }

}
function myrefresh()
{
       window.location.reload();
}


 //查询按钮事件
/* $('#search_btn').click(function(){
    $('#mytab').bootstrapTable('refresh', {url: '../index.php/admin/index/userManagement'});
}) */
//tableHeight函数
function tableHeight(){
    //可以根据自己页面情况进行调整
    return $(window).height() -280;
}	
function gm(){};
gm.ajax=function(s){
    jQuery.ajax(s);
}

 
var crud = {
		 adduser:function(){
			 //随机数防止页面缓存
			 var url = actionUrl +'/addUserPage.html?n='+Math.random();
			 openForm(url,"user添加");
		 },
		 updateuser:function(){
			 var check = $('#user_table').bootstrapTable('getSelections');
			 if(check.length > 1){
				 layer.msg('请只选择一个要修改的数据！');
			 }else if(check.length ==  1) {
				 var id = check[0].userId;
				 var url = actionUrl +'/addUserPage.html?n='+Math.random()+'&id='+id;
				 openForm(url,"修改user");
			 }else{
				 layer.msg('请选择一个要修改的数据！');
			 }
		 },
		deluser:function(){
			var check = $('#user_table').bootstrapTable('getSelections');
				if(check.length > 1){
					layer.msg('请只选择一个要修改的数据！');
				}else if(check.length ==  1) {
					var id = check[0].userId;
					layer.confirm('确认删除吗？', {
						btn: ['确定','取消'] //按钮
					},function(){
						gm.ajax({
							url:'/lender/userController/delUserById.do',
							type:'get',
							data:{id,id},
							dataType:'json',
							success:function(data){
								layer.msg(data.msg, {icon: 1});
								$('#user_table').bootstrapTable('refresh');  
							},
							error:function(){
								layer.msg('连接超时！', {icon: 2});
							}});
					}, function(){
						  
					});
				}else{
		 			layer.msg('请选择一个要修改的数据！');
				}
	
		},
		endisuser:function(status){
			var check = $('#user_table').bootstrapTable('getSelections');
				if(check.length > 1){
					layer.msg('请只选择一个要修改的数据！');
				}else if(check.length ==  1) {
					var id = check[0].userId;
					var msg ='';
					if (status==1) {
						msg = '确定禁用此数据?';
					} else{
						msg = '确定启用此数据?';
					}
					layer.confirm(msg, {
						btn: ['确定','取消'] //按钮
					},function(){
						gm.ajax({
							url:'/lender/userController/endisUserById.do',
							type:'get',
							data:{id,id,status:status},
							dataType:'json',
							success:function(data){
								layer.msg(data.msg, {icon: 1});
								$('#user_table').bootstrapTable('refresh');  
							},
							error:function(){
								layer.msg('连接超时！', {icon: 2});
							}});
					}, function(){
						  
					});
				}else{
		 			layer.msg('请选择一个要修改的数据！');
				}
	
		}
}
 
 
 
/*
 * 弹窗
 */
function openForm(url,title){
	 	var w =  (size.width * 0.5)+'px';
		var h =  (size.height * 0.8 )+'px';
		layer.open({
			type:2,
			anim:4,
			title:title,
			skin:'self-defined',//样式
			//area:'auto',
			area:[w,h],
			content:url,
			btn:['确认','取消'],
			yes:function(index,layero){
				//do something
				var body = layer.getChildFrame('body', index);
                var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象，执行iframe页的方法：
                var json =  iframeWin.checkIsNull();
                if(json.type == true){
                	 var type =  iframeWin.addVIPById();//调用子页面的方法，得到子页面返回的ids
                	 console.log(type);
                     if(type == 1){
                    	 layer.msg("保存成功！",{icon:1});
                     }else{
                     	layer.msg("保存失败！",{icon:3});
                     }
                    $('#user_table').bootstrapTable('refresh'); 
     				layer.close(index);
                }
			},
			btn2:function(index,layero){
				layer.close(index);
				return false;
			}
			
		});
}

function fmtDate(obj){
    var date =  new Date(obj);
    var y = 1900+date.getYear();
    var m = "0"+(date.getMonth()+1);
    var d = "0"+date.getDate();
    return y+"-"+m.substring(m.length-2,m.length)+"-"+d.substring(d.length-2,d.length);
}		




</script>

</html>
